package design.pattern.TemplateMethod;


import java.math.BigDecimal;

public abstract class Order {


    public static void main(String[] args) {
        System.out.println("手机订单金额为："+new PhoneOrder().total());

        System.out.println("汽车订单金额为："+new CarOrder().total());

    }

    /**
     * 获取单价
     * @return
     */
    public abstract BigDecimal getPrice();

    /**
     * 获取数量
     * @return
     */
    public abstract int getNum();

    /**
     * 计算订单的金额
     * @return
     */
    public final double total(){

        // 单价*数量
        BigDecimal price = getPrice();
        int num = getNum();
        return price.multiply(new BigDecimal(num)).doubleValue();
    }
}

class PhoneOrder extends Order{

    @Override
    public BigDecimal getPrice() {
        return new BigDecimal(1000);
    }

    @Override
    public int getNum() {
        return 2;
    }
}

class CarOrder extends Order{

    @Override
    public BigDecimal getPrice() {
        return new BigDecimal(1000000.15);
    }

    @Override
    public int getNum() {
        return 1;
    }
}




